#include<bits/stdc++.h>

using namespace std;
using ll =long long;
ll MOD = 1000;

/**
 * 快速幂算法O(log(n))
 * @param a  底数
 * @param n  指数
 * @return  a^n%MOD
 */
ll power(ll a, int n) {
    a %= MOD;
    if (n == 0 || a == 1)return 1;
    if (n == 1 || a == 0)return a;
    ll temp = power(a, n / 2);
    if (n % 2 == 0) {
        return temp * temp % MOD;
    } else {
        return temp * temp * a % MOD;
    }
}


int main() {
    ll a, b;
    while (cin >> a >> b) {
        if (a == 0 && b == 0)break;
        cout << power(a, b) << endl;
    }

}